include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-shadowsocks
PKG_VERSION:=1.0
PKG_RELEASE:=1

include $(INCLUDE_DIR)/package.mk

define Package/luci-app-shadowsocks
SECTION:=LuCI
CATEGORY:=LuCI
SUBMENU:=3. Applications
TITLE:=LuCI Support for shadowsocks
DEPENDS:=+shadowsocks
PKGARCH:=all
endef

define Package/luci-app-shadowsocks/description
LuCI Support for shadowsocks
endef

define Build/Compile
endef

define Package/luci-app-shadowsocks/postinst
#!/bin/sh
( . /etc/uci-defaults/luci-shadowsocks ) && rm -f /etc/uci-defaults/luci-shadowsocks
exit 0
endef

define Package/luci-app-shadowsocks/postrm
#!/bin/sh
uci -q batch <<-EOF >/dev/null
	delete ucitrack.@shadowsocks[-1]
	commit ucitrack
EOF
rm -f /tmp/luci-indexcache
rm -rf /tmp/luci-modulecache
exit 0
endef

define Package/luci-app-shadowsocks/install
	$(CP) ./root/* $(1)
	$(INSTALL_DIR) $(1)/etc/uci-defaults
	$(INSTALL_BIN) ./files/luci-shadowsocks.uci $(1)/etc/uci-defaults/luci-shadowsocks
	$(INSTALL_DIR) $(1)/www/cgi-bin
	$(INSTALL_BIN) ./root/www/cgi-bin/shadowsocks $(1)/www/cgi-bin/shadowsocks
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) ./files/shadowsocks-web $(1)/usr/bin/ss-web
endef

$(eval $(call BuildPackage,luci-app-shadowsocks))
